//
//  PasswordModifyViewModel.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 13.04.25.
//

import Foundation
class PasswordModifyViewModel : KoiAccountingBaseViewModel {
    
    @Published var isLoading = false
    
    @Published var state = ""
    
    func passwordModify(oldPassword: String, newPassowrd: String) {
        isLoading = true
        KoiAccountingNetApi.standard.passwordModify(oldPassword: LoginUtils.encrypt(pwd: oldPassword), newPassword: LoginUtils.encrypt(pwd: newPassowrd)) { result in
            switch result {
            case .success:
                KoiAccountingUserManager.standard.updateUser(hasPw: 1)
                self.isLoading = false
                self.state = "success"
            case .failure(let error):
                self.isLoading = false
                self.state = error.netErrorMsg()
            }
        }
    }
}
